package com.chexiehui.jc.mvp.forum;

import com.chexiehui.jc.Constants;
import com.chexiehui.jc.base.ApiCallback;
import com.chexiehui.jc.base.BaseModel;
import com.chexiehui.jc.base.BasePresenter;
import com.chexiehui.jc.entity.ForumInfo;

/**
 * @Description 关注的论坛主页
 * @Auth SongJun
 * @Date 2019/11/20 10:05
 **/
public class ForumTribuneDetailsPresenter extends BasePresenter<ForumTribuneDetailsCovenant.View, ForumTribuneDetailsCovenant.Stores>
        implements ForumTribuneDetailsCovenant.Presenter {

    public ForumTribuneDetailsPresenter(ForumTribuneDetailsCovenant.View view) {
        attachView(view);
    }

    @Override
    public void getForumInfo() {
        addSubscription(appStores.getForumInfo(mvpView.getForumId()),
                new ApiCallback<BaseModel<ForumInfo>>(mvpView) {
                    @Override
                    public void onSuccess(BaseModel<ForumInfo> model) {
                        if (model.getResultCode() == 0) {
                            if (model.getData() != null) {
                                mvpView.onGetForumInfoSuccess(model);
                            } else {
                                onFailure(Constants.PAGE_DATA_EMPTY, "没有找到任何数据");
                            }
                        } else {
                            onFailure(model.getResultCode(), model.getResultInfo());
                        }
                    }

                    @Override
                    public void onFailure(int code, String msg) {
                        mvpView.onGetForumInfoFailure(new BaseModel<>(code, msg));
                    }
                });
    }

    @Override
    public void doFollowForum(String objId) {
        addSubscription(appStores.doFollowForum(objId, "1"),
                new ApiCallback<BaseModel<String>>(mvpView) {
                    @Override
                    public void onSuccess(BaseModel<String> model) {
                        if (model.getResultCode() == 0) {
                            model.setData(objId);
                            mvpView.onDoFollowForumSuccess(model);
                        } else {
                            onFailure(model.getResultCode(), model.getResultInfo());
                        }
                    }

                    @Override
                    public void onFailure(int code, String msg) {
                        mvpView.onDoFollowForumFailure(new BaseModel<>(code, msg));
                    }
                });
    }
}